import requests
import time
import re
import os

root = "./images"
if not os.path.exists(root):
    os.mkdir(root)
thumb_root = os.path.join(root,'thumb_images')
if not os.path.exists(thumb_root):
    os.mkdir(thumb_root)
preview_root = os.path.join(root,'preview_images')
if not os.path.exists(preview_root):
    os.mkdir(preview_root)

url = "https://www.hdbz.net/"
res = requests.get(url)
html = res.content.decode('utf-8')

r = re.findall(r'<img src="/templets/images/gray.gif" data-original="(.*?)\?x-oss-process=style/w_auto-h_350" alt="(.*?)" class="lazy" />', html)
pr = re.findall(r'<img src="/templets/images/gray.gif" data-original="(.*?)" alt="(.*?)" class="lazy" />', html)
# print(r)
# for item in r:
#     thumb_url = item[0]
#     thumb_name = item[1]
#     thumb_res = requests.get(thumb_url)
#     with open(f'{thumb_root}/thumb_{thumb_name}.jpg','wb') as f:
#         f.write(thumb_res.content)
#     time.sleep(1)
for item in pr:
    preview_url = item[0]
    preview_name = item[1]
    preview_res = requests.get(preview_url)
    with open(f'{preview_root}/preview_{preview_name}.jpg','wb') as f:
        f.write(preview_res.content)
    time.sleep(1)


